﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.BLL;
using BDCS.Model;

namespace BDCS.UI
{
    public partial class AlterBuildDesignDcriterionSubTypes : Form
    {
        #region 成员字段
        private BDCS.BLL.T_BuildDesignDcriterionSubTypes bllBuildDesignDcriterionSubType;
        private BDCS.Model.T_BuildDesignDcriterionSubTypes modelBuildDesignDcriterionSubType;
        private int dtid;
        private int dstid;
        private string dstName;
        private string dstNameTwo;
        private string dstDescribe;
        private string dstDescribeTwo; 
        #endregion
        #region 构造函数
        public AlterBuildDesignDcriterionSubTypes()
        {
            InitializeComponent();
        }
        public AlterBuildDesignDcriterionSubTypes(BDCS.Model.T_BuildDesignDcriterionSubTypes BuildDesignDcriterionSubType)
        {
            this.modelBuildDesignDcriterionSubType = BuildDesignDcriterionSubType;
            InitializeComponent();
        } 
        #endregion
        #region 成员事件
        private void AlterBuildDesignDcriterionSubTypes_Load(object sender, EventArgs e)
        {
            this.dtid = this.modelBuildDesignDcriterionSubType.DTID;
            this.dstid = this.modelBuildDesignDcriterionSubType.DSTID;
            this.dstDescribe = this.modelBuildDesignDcriterionSubType.DSTDescribe;
            this.dstName = this.modelBuildDesignDcriterionSubType.DSTName;
            this.dstDescribeTwo = this.modelBuildDesignDcriterionSubType.DSTDescribe;
            this.dstNameTwo = this.modelBuildDesignDcriterionSubType.DSTName;
            txtBuildDesignDcriterionSubTypeName.Text = this.dstName;
            txtBuildDesignDcriterionSubTypeDescribe.Text = this.dstDescribe;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.dstName != txtBuildDesignDcriterionSubTypeName.Text.Trim() || dstDescribe != txtBuildDesignDcriterionSubTypeDescribe.Text.Trim())
            {
                modelBuildDesignDcriterionSubType = new Model.T_BuildDesignDcriterionSubTypes();
                modelBuildDesignDcriterionSubType.DTID = this.dtid;
                modelBuildDesignDcriterionSubType.DSTID = this.dstid;
                modelBuildDesignDcriterionSubType.DSTName = txtBuildDesignDcriterionSubTypeName.Text.Trim();
                modelBuildDesignDcriterionSubType.DSTDescribe = txtBuildDesignDcriterionSubTypeDescribe.Text.Trim();
                bllBuildDesignDcriterionSubType = new BLL.T_BuildDesignDcriterionSubTypes();
                try
                {
                    if (bllBuildDesignDcriterionSubType.Update(modelBuildDesignDcriterionSubType) == true)
                    {
                        this.dstName = txtBuildDesignDcriterionSubTypeName.Text.Trim();
                        this.dstDescribe = txtBuildDesignDcriterionSubTypeDescribe.Text.Trim();
                        BDCS.Common.TreeViewState.IsChangedDcriterion = true;
                        MessageBox.Show("修改成功！");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            else
            {
                MessageBox.Show("没有修改内容，不需要提交！");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtBuildDesignDcriterionSubTypeName.Text = dstNameTwo;
            this.txtBuildDesignDcriterionSubTypeDescribe.Text = dstDescribeTwo;
            if (dstName != dstNameTwo || dstDescribe != dstDescribeTwo)
            {
                modelBuildDesignDcriterionSubType = new Model.T_BuildDesignDcriterionSubTypes();
                modelBuildDesignDcriterionSubType.DTID = this.dtid;
                modelBuildDesignDcriterionSubType.DSTID = this.dstid;
                modelBuildDesignDcriterionSubType.DSTName = this.dstNameTwo;
                modelBuildDesignDcriterionSubType.DSTDescribe = this.dstDescribeTwo;
                bllBuildDesignDcriterionSubType = new BLL.T_BuildDesignDcriterionSubTypes();
                try
                {
                    bllBuildDesignDcriterionSubType
                        .Update(modelBuildDesignDcriterionSubType);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        } 
        #endregion
    }
}
